{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "19a20dcc-b433-417d-971e-f13fbd9c603d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle as pkl\n",
    "import pandas as pd\n",
    "import datetime\n",
    "import random\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "c6d648ad-781d-4556-99b7-981d642487e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pkl.load(open('./data.pkl', 'rb'))\n",
    "x_mean = pkl.load(open('./x_mean', 'rb'))\n",
    "x_std = pkl.load(open('./x_std', 'rb'))\n",
    "end_date = datetime.datetime.strptime('2019-12-27',  \"%Y-%m-%d\" )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "3572d01a-906d-4bb5-9f0c-259b994ab946",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list = list(data['2019-12-27']['open'].keys())\n",
    "date_list = list(data.keys())[:-2]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "1d5ed765-882c-41c0-ac26-95aff909a589",
   "metadata": {},
   "outputs": [],
   "source": [
    "pkl.dump(name_list, open('./name_list.pkl', 'wb'))\n",
    "pkl.dump(date_list, open('./date_list.pkl', 'wb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "2ac3657a-487c-44d2-baf3-81665e7bcf2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2429"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(date_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "9467a0fb-7c98-447f-af5b-87af3be5640d",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-120-7d348c7b32cb>:10: RuntimeWarning: invalid value encountered in true_divide\n",
      "  sd_zscore = (sd - x_mean) / x_std\n"
     ]
    }
   ],
   "source": [
    "x = np.zeros((24,2429,35))\n",
    "y = [[] for _ in range(24)]\n",
    "\n",
    "for i, (date, stock) in enumerate(data.items()):\n",
    "    if date > '2019-12-27':\n",
    "        continue\n",
    "    date_now = datetime.datetime.strptime(date,  \"%Y-%m-%d\" )\n",
    "    stock_data = stock.values\n",
    "    for si, sd in enumerate(stock_data):\n",
    "        sd_zscore = (sd - x_mean) / x_std\n",
    "        sd_zscore[np.isnan(sd_zscore)] = 0\n",
    "        x[si][i] = sd_zscore\n",
    "        open_now = sd[0]\n",
    "        for di in range(1, 15):\n",
    "            date_after = (date_now + datetime.timedelta(days=di)).strftime('%Y-%m-%d')\n",
    "            if date_after in data.keys():\n",
    "                break\n",
    "        label = 1 if data[date_after].values[si][0] > open_now else 0\n",
    "        y[si].append(label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "b40844ad-5f1d-4bc9-ac39-b41aaeadfa67",
   "metadata": {},
   "outputs": [],
   "source": [
    "pkl.dump(np.array(x), open('./x.pkl', 'wb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "b745de05-857b-48fb-a6eb-0eecf7fd2495",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_n2n = []\n",
    "y_n2n = []\n",
    "\n",
    "for i in range(len(y)):\n",
    "    for j in range(len(y[i])):\n",
    "        x_n2n.append(x[i][:j + 1])\n",
    "        y_n2n.append(np.array(y[i][:j + 1]))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "1684a51d-44c6-46f9-a2d1-07e0ddb10a33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "58296"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(x_n2n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "8c9dabbe-e6ee-4646-ba81-a172783abe85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2431"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(date_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "b5c7e8bd-19c4-421c-aa58-e9ae7e615a6f",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_date = {}\n",
    "\n",
    "for di, date in enumerate(date_list):\n",
    "    x_date[date] = {}\n",
    "    for ni, name in enumerate(name_list):\n",
    "        x_date[date][name] = x_n2n[ni * len(date_list) + di] if len(x_n2n[ni * len(date_list) + di]) < 50 else x_n2n[ni * len(date_list) + di][:50]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "0c3199dc-889e-45ee-a122-9d4fa79b351b",
   "metadata": {},
   "outputs": [],
   "source": [
    "pkl.dump(np.array(x_date), open('./x_date.pkl', 'wb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "34caf49a-d456-4d49-83b9-775f6dbc1e7a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'600150.XSHG': array([[ 0.13600545,  0.12801541,  0.13254052,  0.13394204, -0.53001304,\n",
       "         -0.36871438, -1.25758973,  0.1310748 ,  0.13510611, -0.00580407,\n",
       "          0.13444493, -0.19959468, -0.65778553, -0.33354378, -0.31855699,\n",
       "          0.        ,  0.        , -0.12655778,  0.50084409, -0.18723005,\n",
       "         -0.14237069,  1.4856502 ,  0.06423435,  0.48615562, -0.23046794,\n",
       "         -0.11460591, -0.30649744,  0.13391944, -0.24896672,  0.13244311,\n",
       "         -0.23084379,  0.13706185, -0.08919941, -0.28919153,  0.6234477 ],\n",
       "        [ 0.1288887 ,  0.12976302,  0.12632   ,  0.13075519, -0.53293372,\n",
       "         -0.37726904, -1.25758973,  0.12874313,  0.12845501, -0.00580456,\n",
       "          0.12783259, -0.19959468,  0.15088243,  0.07293389, -0.64444095,\n",
       "          0.        ,  0.        , -0.12655778,  0.47636954, -0.2401347 ,\n",
       "         -0.25839108,  1.47705941,  0.05472283,  0.45939568, -0.21051752,\n",
       "         -0.10050844, -0.23044368,  0.13354007, -0.14545482,  0.13213923,\n",
       "         -0.05062976,  0.04306343, -0.06357206, -0.25623619,  0.6234477 ]]),\n",
       " '600900.XSHG': array([[-2.15632019e-01, -2.16845400e-01, -2.17190971e-01,\n",
       "         -2.15431068e-01,  6.07721670e-02, -2.13393712e-01,\n",
       "         -1.34229374e+00, -2.16461106e-01, -2.16002358e-01,\n",
       "         -5.83013939e-03, -2.16657161e-01, -1.99594678e-01,\n",
       "         -5.65994973e-01, -5.69131386e-02, -6.31299068e-01,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "          5.72182121e-01, -1.05111013e-01, -5.32720809e-01,\n",
       "         -4.58280845e-01,  2.24806853e-01, -1.77105176e+00,\n",
       "         -1.25465756e-01,  3.64613300e-01, -2.15460323e-01,\n",
       "         -2.17480224e-01,  6.58641652e-03, -2.17084598e-01,\n",
       "         -4.72294923e-02,  7.76253703e-01,  2.37828448e-02,\n",
       "          4.14657924e-04, -2.94061708e-01],\n",
       "        [-2.16682032e-01, -2.16728893e-01, -2.17766945e-01,\n",
       "         -2.16139257e-01,  3.29502664e-01, -9.84661981e-02,\n",
       "         -1.34229374e+00, -2.17160608e-01, -2.16935847e-01,\n",
       "         -5.83020239e-03, -2.17564737e-01, -1.99594678e-01,\n",
       "          4.94925947e-02, -6.10342986e-03, -5.43451860e-01,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "          5.95186689e-01, -1.85010787e-01, -5.72352519e-01,\n",
       "         -4.61903578e-01,  2.21722580e-01, -1.75093539e+00,\n",
       "         -9.08150366e-02,  5.81742695e-01, -1.70793680e-01,\n",
       "         -2.17476552e-01,  4.87773655e-02, -2.16850847e-01,\n",
       "         -3.02281686e-02,  4.69588654e-01,  2.56062920e-02,\n",
       "          4.82108488e-01,  1.64692996e-01]]),\n",
       " '600048.XSHG': array([[-0.22134875, -0.22290377, -0.22237474, -0.2215687 ,  0.50900073,\n",
       "         -0.05490571, -2.15114507, -0.22205712, -0.2214866 , -0.00583055,\n",
       "         -0.22223227, -0.19959468, -0.98424541, -0.08514075,  0.01514975,\n",
       "          0.        ,  0.        , -0.12655778, -0.02112464, -0.27273327,\n",
       "          1.14526745,  0.45381477, -0.48545645,  0.3795673 , -0.12651578,\n",
       "         -0.0524003 , -1.26127451, -0.22177933, -0.89788679, -0.22253099,\n",
       "         -0.11863505, -0.25869519, -0.02908496, -1.36184901, -1.21157112],\n",
       "        [-0.22286544, -0.22476788, -0.22433305, -0.22463752,  1.8869539 ,\n",
       "          0.45593847, -2.15114507, -0.2250883 , -0.22300352, -0.00583066,\n",
       "         -0.22365846, -0.19959468, -1.23594353, -0.10207732,  0.81425382,\n",
       "          0.        ,  0.        , -0.12655778,  0.31452092, -0.35536253,\n",
       "          1.31438544,  0.46220689, -0.57846851,  0.32851992,  0.00893703,\n",
       "         -0.1681309 , -1.532495  , -0.2223851 , -1.17538854, -0.22306862,\n",
       "         -0.14413704, -1.11919195, -0.03426788, -1.25833184, -1.67032582]]),\n",
       " '600340.XSHG': array([[-2.70582666e-01, -2.70322128e-01, -2.71102150e-01,\n",
       "         -2.69843569e-01, -3.75462891e-01, -4.76512611e-01,\n",
       "         -2.78072451e+00, -2.70439343e-01, -2.70728139e-01,\n",
       "         -5.83425029e-03, -2.70593080e-01, -1.99594678e-01,\n",
       "          6.46173237e-01, -4.57906667e-04, -2.78133139e-01,\n",
       "          0.00000000e+00,  0.00000000e+00,  7.90152945e+00,\n",
       "         -2.04218885e-01, -1.13956552e-01, -2.90892671e-01,\n",
       "         -1.09852611e+00,  5.16296736e-01, -9.03177309e-01,\n",
       "         -3.93639687e-02, -6.14087066e-02,  6.49176147e-01,\n",
       "         -2.71672465e-01,  3.43081737e-01, -2.70917428e-01,\n",
       "         -3.87288305e-02,  9.80965203e-01, -9.45121177e-05,\n",
       "         -1.82712768e-01, -7.52816411e-01],\n",
       "        [-2.70465998e-01, -2.70555142e-01, -2.71217345e-01,\n",
       "         -2.70079632e-01, -3.44525846e-01, -4.73917019e-01,\n",
       "         -2.78072451e+00, -2.70672510e-01, -2.70494767e-01,\n",
       "         -5.83423454e-03, -2.70333773e-01, -1.99594678e-01,\n",
       "         -6.74804004e-01, -2.30399994e-02,  6.97517077e-02,\n",
       "          0.00000000e+00,  0.00000000e+00,  7.90152945e+00,\n",
       "         -1.07954005e-01, -1.62872059e-01, -2.95497931e-01,\n",
       "         -1.10448074e+00,  5.48880647e-01, -9.16529827e-01,\n",
       "         -3.93639687e-02, -8.34987524e-02,  4.05186122e-01,\n",
       "         -2.71650437e-01,  1.27452471e-01, -2.70917428e-01,\n",
       "         -3.36284334e-02,  6.43780399e-01,  1.72115616e-04,\n",
       "         -2.17007322e-01, -7.52816411e-01]]),\n",
       " '600569.XSHG': array([[-0.22181543, -0.2217387 , -0.22237474, -0.22109658, -0.36468289,\n",
       "         -0.40823615,  0.68736761, -0.2214742 , -0.22195335, -0.00583059,\n",
       "         -0.22262123, -0.19959468,  0.05501493, -0.00610343, -0.30850747,\n",
       "          0.        ,  0.        , -0.12655778, -0.48820154, -0.09239557,\n",
       "         -0.31884575,  0.49333674,  0.92521684,  0.6216269 ,  0.04883786,\n",
       "          0.20573336,  0.51155199, -0.22386708,  0.47757992, -0.22267124,\n",
       "         -0.02342764,  0.84998719,  0.02870693,  0.18003472,  0.164693  ],\n",
       "        [-0.22181543, -0.2218552 , -0.22272032, -0.2219228 , -0.40602452,\n",
       "         -0.42595517,  0.68736761, -0.22217371, -0.22183666, -0.00583057,\n",
       "         -0.22236192, -0.19959468, -0.09433496, -0.01739448,  0.02298052,\n",
       "          0.        ,  0.        , -0.12655778, -0.45736964, -0.11550495,\n",
       "         -0.32497348,  0.48384112,  0.95491754,  0.59379586,  0.05303795,\n",
       "          0.16063293,  0.48478455, -0.22370799,  0.46241917, -0.22215699,\n",
       "          0.00717474,  0.72750478,  0.03582419,  0.07648384, -0.29406171]]),\n",
       " '600019.XSHG': array([[-0.21073196, -0.21276765, -0.21223759, -0.21129997,  0.55937309,\n",
       "          0.0397518 , -0.48226445, -0.21203093, -0.21121823, -0.00582978,\n",
       "         -0.21185998, -0.19959468, -0.91357928, -0.09078628, -0.11007549,\n",
       "          0.        ,  0.        , -0.12655778, -0.56034366,  0.05596587,\n",
       "         -0.44225157, -0.00375433,  1.3050716 ,  0.51413569, -0.37852101,\n",
       "          1.18441419,  1.22330896, -0.21488705,  0.62861142, -0.21292383,\n",
       "          0.02247593,  1.00605714,  0.03027086,  1.89888538,  0.164693  ],\n",
       "        [-0.21271532, -0.2134667 , -0.21327435, -0.21342453,  0.76877501,\n",
       "          0.12405607, -0.48226445, -0.2136631 , -0.21285183, -0.0058299 ,\n",
       "         -0.21341582, -0.19959468, -0.41150004, -0.04562209,  0.57579411,\n",
       "          0.        ,  0.        , -0.12655778, -0.43686529, -0.0390201 ,\n",
       "         -0.31041065, -0.01291505,  1.12391717,  0.48609375, -0.36697077,\n",
       "          1.07458384,  1.05222553, -0.21476835,  0.46264984, -0.21266671,\n",
       "          0.04967805,  0.63370827,  0.02018124,  1.5816058 , -0.29406171]]),\n",
       " '600115.XSHG': array([[-2.14932011e-01, -2.16146358e-01, -2.16499802e-01,\n",
       "         -2.14840911e-01, -5.02064979e-01, -4.61694365e-01,\n",
       "          7.87073261e-01, -2.15761604e-01, -2.15418928e-01,\n",
       "         -5.83032840e-03, -2.12248937e-01, -1.99594678e-01,\n",
       "         -4.93695094e-01, -5.12676154e-02, -5.62043780e-01,\n",
       "          0.00000000e+00,  0.00000000e+00,  7.90152945e+00,\n",
       "          1.87863874e-01, -7.60098154e-02, -3.15630575e-01,\n",
       "         -8.40174437e-01,  4.11290731e-01, -8.93350079e-01,\n",
       "          4.68846579e-01, -8.93052996e-02,  1.66453055e-01,\n",
       "         -2.17029876e-01,  6.83780492e-02, -2.16009344e-01,\n",
       "         -4.21290952e-02,  5.28485676e-01,  3.41113766e-03,\n",
       "         -2.65400651e-01, -2.94061708e-01],\n",
       "        [-2.16098692e-01, -2.15913344e-01, -2.17190971e-01,\n",
       "         -2.15549100e-01, -5.13664177e-01, -4.67113026e-01,\n",
       "          7.87073261e-01, -2.16344522e-01, -2.16235730e-01,\n",
       "         -5.83039140e-03, -2.13026859e-01, -1.99594678e-01,\n",
       "          1.17301724e-01, -4.57906667e-04, -5.52134900e-01,\n",
       "          0.00000000e+00,  0.00000000e+00,  7.90152945e+00,\n",
       "          1.53740224e-01, -1.11153186e-01, -3.69985877e-01,\n",
       "         -8.47767305e-01,  3.95691095e-01, -9.15165030e-01,\n",
       "          2.52542090e-01, -1.00059014e-01,  2.20185490e-01,\n",
       "         -2.16898932e-01,  1.31907536e-01, -2.16079469e-01,\n",
       "         -1.49269773e-02,  4.68190914e-01,  7.93103394e-03,\n",
       "         -2.56172157e-01, -2.94061708e-01]]),\n",
       " '600118.XSHG': array([[-1.95915121e-01, -1.97388726e-01, -1.97723046e-01,\n",
       "         -1.96309973e-01, -3.38115523e-01, -3.59757052e-01,\n",
       "         -1.85695095e+00, -1.97108217e-01, -1.95932349e-01,\n",
       "         -5.82865096e-03, -1.96560845e-01, -1.99594678e-01,\n",
       "         -7.07041936e-01, -8.51407546e-02, -3.89954119e-01,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "         -1.38294226e+00,  6.79821026e-02, -4.45154682e-01,\n",
       "          1.56087160e+00,  2.01127750e+00,  5.74942329e-01,\n",
       "          3.73756442e+00, -1.21460745e-02,  9.88905329e-01,\n",
       "         -2.01335016e-01,  1.19126746e+00, -1.97379398e-01,\n",
       "          5.81787146e-02,  9.32775047e-01,  1.51246695e-01,\n",
       "         -1.93131556e-01,  6.23447700e-01],\n",
       "        [-1.97081801e-01, -1.94592557e-01, -1.94843175e-01,\n",
       "         -1.96073910e-01, -2.34855289e-01, -2.96884347e-01,\n",
       "         -1.85695095e+00, -1.95242879e-01, -1.97449268e-01,\n",
       "         -5.82876122e-03, -1.98116689e-01, -1.99594678e-01,\n",
       "          1.27117915e+00,  1.23743604e-01,  1.01000809e+00,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "         -1.77871882e+00,  1.67501314e-01, -6.19341297e-01,\n",
       "          1.54610138e+00,  2.02723368e+00,  5.77606558e-01,\n",
       "          3.65251266e+00,  1.14305513e-03,  1.26861761e+00,\n",
       "         -2.00270335e-01,  1.61917338e+00, -1.96421019e-01,\n",
       "          1.34684671e-01,  9.64877633e-01,  1.70330123e-01,\n",
       "         -1.02592610e-01,  6.23447700e-01]]),\n",
       " '600151.XSHG': array([[-0.16126471, -0.16068901, -0.16178226, -0.16090054, -0.49481573,\n",
       "         -0.42950349,  0.58014495, -0.16120045, -0.16197669, -0.00582612,\n",
       "         -0.16259159, -0.19959468,  0.40112366,  0.0503518 , -0.15445799,\n",
       "          0.        ,  0.        , -0.12655778, -0.27122236, -0.32531349,\n",
       "          0.55227645, -2.37918238, -0.13046621,  1.54608723, -0.23256798,\n",
       "         -0.08507524, -0.39005598, -0.16086492, -0.33668073, -0.16187264,\n",
       "         -0.15603796,  0.10505477, -0.08682885, -0.22887724,  0.6234477 ],\n",
       "        [-0.16033137, -0.15987346, -0.16189745, -0.16031038, -0.49948217,\n",
       "         -0.43310447,  0.58014495, -0.16096728, -0.16069315, -0.00582604,\n",
       "         -0.16129505, -0.19959468,  0.24531748,  0.02776971, -0.42116226,\n",
       "          0.        ,  0.        , -0.12655778, -0.29764432, -0.30217951,\n",
       "          0.36315821, -2.37121033,  0.05119623,  1.51050753, -0.20526741,\n",
       "         -0.08070788, -0.30832738, -0.16071929, -0.16421454, -0.16149864,\n",
       "         -0.05062976,  0.38837237, -0.04432253, -0.2511005 ,  0.6234477 ]]),\n",
       " '002558.XSHE': array([[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        , -0.12655778,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ],\n",
       "        [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        , -0.12655778,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ]]),\n",
       " '603110.XSHG': array([[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        , -0.12655778,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ],\n",
       "        [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        , -0.12655778,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ]]),\n",
       " '000001.XSHE': array([[-0.19288175, -0.19599064, -0.19449759, -0.19442147,  0.1371193 ,\n",
       "         -0.08038735, -1.8308308 , -0.19500971, -0.19348194, -0.00582847,\n",
       "         -0.19422708, -0.19959468, -1.15167836, -0.13595046,  0.27310469,\n",
       "          0.        ,  0.        , -0.12655778,  0.38246668, -0.10964748,\n",
       "          0.14924532,  0.89390825, -0.12595307, -0.04835558, -0.27351883,\n",
       "         -0.09350798, -0.23772044, -0.19529326, -0.40972492, -0.19548602,\n",
       "         -0.14243691, -0.12012075, -0.05951468, -0.5526326 , -0.75281641],\n",
       "        [-0.19568178, -0.19750523, -0.19703188, -0.19784438,  1.06572544,\n",
       "          0.42945509, -1.8308308 , -0.19780772, -0.19604904, -0.00582866,\n",
       "         -0.1966905 , -0.19959468, -0.70794511, -0.08514075,  0.73544545,\n",
       "          0.        ,  0.        , -0.12655778,  0.55253212, -0.13465661,\n",
       "          0.3444062 ,  0.89672151, -0.16813428, -0.06463117, -0.07401469,\n",
       "         -0.10175947, -0.45135188, -0.19565917, -0.63708774, -0.19548602,\n",
       "         -0.14073677, -0.60104496, -0.06651532, -0.6361257 , -0.75281641]]),\n",
       " '600030.XSHG': array([[-0.0923139 , -0.09684316, -0.09370212, -0.09409473,  1.45809941,\n",
       "          2.01399263, -1.04287402, -0.09416484, -0.09383201, -0.00582107,\n",
       "         -0.09452342, -0.19959468, -0.6349873 , -0.15288703,  0.09077023,\n",
       "          0.        ,  0.        , -0.12655778, -0.48071343, -0.03582914,\n",
       "         -0.5124936 ,  2.15401224,  1.1538444 ,  0.57543212,  0.54339813,\n",
       "          1.31668122,  0.72333848, -0.101397  ,  0.64437711, -0.09815214,\n",
       "          0.12278374,  1.22501836,  0.17310758,  1.67595788,  0.6234477 ],\n",
       "        [-0.09499727, -0.0876391 , -0.08897913, -0.09680946,  3.27520897,\n",
       "          4.33049407, -1.04287402, -0.09113367, -0.09674916, -0.00582129,\n",
       "         -0.0973758 , -0.19959468,  1.95463853,  0.43424738,  1.90129092,\n",
       "          0.        ,  0.        , -0.12655778, -1.0672231 , -0.09139733,\n",
       "         -0.87780322,  2.13371312,  1.3839826 ,  0.58508331,  0.70720153,\n",
       "          2.05565759,  1.23267804, -0.09902655,  1.37155305, -0.09459913,\n",
       "          0.30809817,  1.22517537,  0.25285724,  2.68590735,  0.6234477 ]]),\n",
       " '601001.XSHG': array([[-3.18798583e-02, -3.67255287e-02, -3.47223669e-02,\n",
       "         -3.31905033e-02, -4.98237405e-01, -3.67794284e-01,\n",
       "         -1.20578211e+00, -3.48237546e-02, -3.53722769e-02,\n",
       "         -5.81673565e-03, -3.60496246e-02, -1.99594678e-01,\n",
       "         -2.08162803e-01, -6.82041850e-02, -3.41481658e-01,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "          1.91607927e-01, -1.92897235e-01,  3.93324076e-01,\n",
       "         -2.02888049e-02, -1.16202962e-01,  1.98320026e+00,\n",
       "         -2.69318741e-01, -1.79762008e-01, -2.07278014e-01,\n",
       "         -3.26247515e-02, -4.68086279e-01, -3.35433973e-02,\n",
       "         -3.70254642e-01, -1.45939170e-01, -2.17239471e-01,\n",
       "         -2.72505538e-01, -7.52816411e-01],\n",
       "        [-3.24631985e-02, -2.70554450e-02, -2.97689894e-02,\n",
       "         -3.00036541e-02, -3.58202559e-01, -1.33711484e-01,\n",
       "         -1.20578211e+00, -2.93443223e-02, -3.65391379e-02,\n",
       "         -5.81682228e-03, -3.72165075e-02, -1.99594678e-01,\n",
       "          1.55161909e+00,  4.56829472e-01,  1.98012306e-03,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "         -2.54788728e-01, -1.63762642e-01, -4.34568978e-02,\n",
       "         -1.18614927e-02,  6.95705015e-02,  1.96958803e+00,\n",
       "         -2.03167368e-01, -5.21692084e-02,  2.71686359e-01,\n",
       "         -3.18623423e-02,  1.15260788e-01, -3.24915183e-02,\n",
       "         -6.08305513e-02,  4.79054286e-01, -1.19251529e-01,\n",
       "         -1.81235221e-01, -2.94061708e-01]]),\n",
       " '002611.XSHE': array([[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        , -0.12655778,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ],\n",
       "        [ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        , -0.12655778,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ,\n",
       "          0.        ,  0.        ,  0.        ,  0.        ,  0.        ]]),\n",
       " '601857.XSHG': array([[-0.16383141, -0.16593183, -0.16569888, -0.16396935, -0.14968178,\n",
       "         -0.16427132, -0.09845556, -0.16504771, -0.16419373, -0.0058263 ,\n",
       "         -0.16492535, -0.19959468, -0.6041649 , -0.0964318 , -0.48000933,\n",
       "          0.        ,  0.        , -0.12655778,  0.42221898, -0.09693438,\n",
       "         -0.45824232,  1.79988461,  0.33773867, -0.9139789 , -0.03516388,\n",
       "          0.70062581,  0.08301339, -0.16650038,  0.04558663, -0.1658464 ,\n",
       "         -0.04892962,  0.64051489,  0.03552093, -0.26366925, -0.75281641],\n",
       "        [-0.16523143, -0.16360169, -0.16512291, -0.16408739,  0.14272041,\n",
       "          0.06583085, -0.09845556, -0.16423162, -0.16594402, -0.00582642,\n",
       "         -0.1664812 , -0.19959468,  0.77098911,  0.10116151, -0.20145212,\n",
       "          0.        ,  0.        , -0.12655778,  0.19667119, -0.11614077,\n",
       "         -0.64678373,  1.81371026,  0.41850613, -0.90425276,  0.02258732,\n",
       "          1.41189031,  0.46439028, -0.16608063,  0.33845657, -0.16498152,\n",
       "          0.01227514,  0.93315545,  0.05501484, -0.0065772 , -0.29406171]]),\n",
       " '600028.XSHG': array([[-0.20898194, -0.21102005, -0.21050967, -0.2095295 ,  1.16866884,\n",
       "          0.34857655, -1.27787488, -0.210049  , -0.20970131, -0.00582967,\n",
       "         -0.21030413, -0.19959468, -0.77042051, -0.07949523, -0.13600109,\n",
       "          0.        ,  0.        , -0.12655778, -0.3500108 ,  0.29471503,\n",
       "         -0.51021461,  0.36237338,  0.93264135, -0.73648915, -0.56857495,\n",
       "          0.90813561,  1.0971271 , -0.21282867,  0.56099845, -0.21100707,\n",
       "         -0.00812645,  0.92176537,  0.05635768,  2.29032793,  0.164693  ],\n",
       "        [-0.21084863, -0.21055402, -0.21131604, -0.2110639 ,  1.70323702,\n",
       "          0.58946059, -1.27787488, -0.21121484, -0.21110154, -0.00582978,\n",
       "         -0.21173032, -0.19959468,  0.23525241,  0.01083314,  0.31531973,\n",
       "          0.        ,  0.        , -0.12655778, -0.36174552,  0.14562685,\n",
       "         -0.52197836,  0.35263367,  0.83777417, -0.74190824, -0.56752493,\n",
       "          1.21544448,  1.18010516, -0.21259738,  0.58984701, -0.2106097 ,\n",
       "          0.03267673,  0.64822703,  0.04974574,  3.05731228,  0.6234477 ]]),\n",
       " '600050.XSHG': array([[-0.20781526, -0.20973847, -0.20935772, -0.20834918,  1.10034595,\n",
       "          0.3255631 ,  0.52336965, -0.20911633, -0.20818439, -0.00582956,\n",
       "         -0.20887794, -0.19959468, -0.87820622, -0.09078628, -0.16090071,\n",
       "          0.        ,  0.        , -0.12655778, -0.39029078,  0.34952432,\n",
       "         -0.46386887,  0.86604124,  0.77688626, -1.12753029, -0.12651578,\n",
       "          1.98335892,  0.92869233, -0.21108602,  0.54771215, -0.20960457,\n",
       "          0.01737554,  0.85617814,  0.07096803,  3.05897979,  0.6234477 ],\n",
       "        [-0.20944861, -0.20705881, -0.20855136, -0.20905737,  2.25354997,\n",
       "          0.90308393,  0.52336965, -0.20841683, -0.20981799, -0.00582968,\n",
       "         -0.21043379, -0.19959468,  1.42133341,  0.11809808,  0.77620565,\n",
       "          0.        ,  0.        , -0.12655778, -0.79358057,  0.25843163,\n",
       "         -0.69374413,  0.85587919,  0.80311799, -1.11076404, -0.09816519,\n",
       "          4.0818437 ,  1.43637382, -0.21060508,  1.01981789, -0.20885657,\n",
       "          0.04457766,  1.08450375,  0.07904273,  3.91479923,  1.0822024 ]]),\n",
       " '000063.XSHE': array([[-0.05813017, -0.05653172, -0.05937406, -0.05903939, -0.31938007,\n",
       "         -0.117707  , -1.38377643, -0.05825707, -0.05905955, -0.00581848,\n",
       "         -0.05977624, -0.19959468,  0.45913552,  0.11809808, -0.11468471,\n",
       "          0.        ,  0.        , -0.12655778, -1.00951694,  0.43906082,\n",
       "         -0.65147409, -0.44313371,  0.99844452, -1.38998949, -0.40057147,\n",
       "         -0.08158806,  1.6989424 , -0.06527373,  1.12854672, -0.06061175,\n",
       "          0.2094905 ,  1.09252851,  0.24823731, -0.19524499,  1.0822024 ],\n",
       "        [-0.05591347, -0.05222096, -0.05349912, -0.05538042, -0.25295901,\n",
       "         -0.0100365 , -1.38377643, -0.05336056, -0.05637577, -0.00581829,\n",
       "         -0.05705352, -0.19959468,  0.74156938,  0.19713541,  0.33016399,\n",
       "          0.        ,  0.        , -0.12655778, -1.18019802,  0.53608245,\n",
       "         -0.71061433, -0.44738767,  1.09496576, -1.37899181, -0.34702035,\n",
       "         -0.06848722,  1.90876807, -0.06292776,  1.30258027, -0.05860149,\n",
       "          0.3199991 ,  1.31340937,  0.27692429, -0.12615979,  1.0822024 ]]),\n",
       " '000651.XSHE': array([[-0.20968195, -0.2118356 , -0.21097045, -0.21035572, -0.18835282,\n",
       "         -0.30977732, -2.23367443, -0.21098167, -0.20993468, -0.00582969,\n",
       "         -0.21056344, -0.19959468, -1.08652156, -0.10772285,  0.07830394,\n",
       "          0.        ,  0.        , -0.12655778, -0.04529765,  0.1474471 ,\n",
       "         -0.37221758, -0.00857367,  0.8168357 , -0.27928416, -0.3060695 ,\n",
       "         -0.09040323,  0.44398975, -0.21249581,  0.2611121 , -0.21067982,\n",
       "         -0.0319283 ,  0.61435027,  0.04113076,  0.09725769,  0.6234477 ],\n",
       "        [-0.21166531, -0.21393272, -0.21269837, -0.21271634,  0.14406796,\n",
       "         -0.16219955, -2.23367443, -0.21342993, -0.21191834, -0.00582984,\n",
       "         -0.2126379 , -0.19959468, -1.17999767, -0.11336837,  0.47854   ,\n",
       "          0.        ,  0.        , -0.12655778,  0.32464745,  0.0468858 ,\n",
       "         -0.06846904, -0.01434212,  0.46426086, -0.31340755, -0.29976937,\n",
       "         -0.09598622,  0.02247688, -0.21289353, -0.18331473, -0.21121745,\n",
       "         -0.03362843,  0.03314528,  0.01342803,  0.101062  ,  0.6234477 ]]),\n",
       " '600111.XSHG': array([[-2.15398683e-01, -2.14515260e-01, -2.14887075e-01,\n",
       "         -2.15076974e-01,  3.31747683e-01, -8.31725444e-02,\n",
       "         -2.26529109e+00, -2.14712351e-01, -2.16352417e-01,\n",
       "         -5.83016302e-03, -2.17046122e-01, -1.99594678e-01,\n",
       "          1.00975371e+00,  7.29338949e-02,  6.76484937e-01,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "         -1.96554884e-01, -1.88438166e-01, -4.26335728e-05,\n",
       "          8.77656466e-01,  4.25305067e-02,  1.38172864e+00,\n",
       "          4.38395947e-01, -1.20753978e-01, -1.80927339e-01,\n",
       "         -2.16360473e-01,  4.57770471e-02, -2.16406720e-01,\n",
       "         -6.93312131e-02,  5.16839842e-01,  6.06836408e-03,\n",
       "         -2.97147607e-01, -2.94061708e-01],\n",
       "        [-2.13065323e-01, -2.13466697e-01, -2.14195906e-01,\n",
       "         -2.12952408e-01,  3.22660103e-01, -7.91473064e-02,\n",
       "         -2.26529109e+00, -2.13313347e-01, -2.14602125e-01,\n",
       "         -5.83003701e-03, -2.15230971e-01, -1.99594678e-01,\n",
       "          5.82569596e-01,  3.90607557e-02, -2.72570399e-01,\n",
       "          0.00000000e+00,  0.00000000e+00, -1.26557777e-01,\n",
       "         -3.38263521e-01, -1.44266945e-01, -2.01728416e-01,\n",
       "          8.66414752e-01,  3.31083562e-01,  1.35206218e+00,\n",
       "          8.71004926e-01, -9.48571100e-02, -5.63347308e-03,\n",
       "         -2.15993342e-01,  2.97383250e-01, -2.15682092e-01,\n",
       "         -3.36284334e-02,  1.05603565e+00,  3.55382919e-02,\n",
       "         -2.84986721e-01,  1.64692996e-01]]),\n",
       " '600518.XSHG': array([[-0.23604893, -0.23688461, -0.23735007, -0.23573248, -0.27446111,\n",
       "         -0.40128448, -1.5465967 , -0.23686325, -0.23630574, -0.00583165,\n",
       "         -0.23701278, -0.19959468, -0.60079315, -0.04562209, -0.63680213,\n",
       "          0.        ,  0.        , -0.12655778,  0.45850363, -0.19703182,\n",
       "         -0.16533079, -2.07018396,  0.15158588, -0.41028716, -0.22731787,\n",
       "         -0.10309825,  0.00904421, -0.23732856, -0.17799831, -0.23674305,\n",
       "         -0.05913042,  0.22342601, -0.01771892, -0.1461835 ,  0.164693  ],\n",
       "        [-0.23698227, -0.2367681 , -0.23781085, -0.23667673, -0.16749369,\n",
       "         -0.36942826, -1.5465967 , -0.23732958, -0.23700586, -0.0058317 ,\n",
       "         -0.23779071, -0.19959468,  0.07853199, -0.00610343, -0.18647304,\n",
       "          0.        ,  0.        , -0.12655778,  0.42402818, -0.28185334,\n",
       "         -0.28039608, -2.06362876,  0.13331615, -0.41972831, -0.19056711,\n",
       "         -0.10362962,  0.04746582, -0.23738241, -0.10484861, -0.2367898 ,\n",
       "         -0.06083055, -0.06971884, -0.01523309, -0.22152721,  0.164693  ]]),\n",
       " '600056.XSHG': array([[-0.17608155, -0.17933014, -0.17813993, -0.177661  , -0.49255935,\n",
       "         -0.4371257 , -1.78487061, -0.17857141, -0.17679583, -0.00582723,\n",
       "         -0.17750176, -0.19959468, -0.97687412, -0.13595046,  0.01559745,\n",
       "          0.        ,  0.        , -0.12655778,  0.06118171, -0.2473779 ,\n",
       "          0.61151125,  0.29556908, -0.11571908, -0.01893664,  0.11603926,\n",
       "         -0.10876785,  0.12365427, -0.17767463, -0.55980933, -0.17828195,\n",
       "         -0.16793889, -0.04322327, -0.20282806, -0.1995105 , -0.29406171],\n",
       "        [-0.18039827, -0.18026219, -0.18067421, -0.17954951, -0.51941476,\n",
       "         -0.45636635, -1.78487061, -0.18066992, -0.17936292, -0.00582742,\n",
       "         -0.18009483, -0.19959468, -0.37625222, -0.05691314, -0.24890961,\n",
       "          0.        ,  0.        , -0.12655778,  0.16681928, -0.26288599,\n",
       "          0.56662179,  0.29567126, -0.17129094, -0.06015244,  0.06353817,\n",
       "         -0.10570925,  0.02658781, -0.17815924, -0.59185484, -0.17872608,\n",
       "         -0.08633254, -0.29702482, -0.19808131, -0.1804079 , -0.75281641]]),\n",
       " '600519.XSHG': array([[ 0.96201516,  0.94542875,  0.9455856 ,  0.95744749, -0.50941837,\n",
       "          0.04339133, -0.61253322,  0.94692729,  0.94619119, -0.00574386,\n",
       "          0.94555817, -0.19959468,  0.01082023,  0.03341523, -0.68171368,\n",
       "          0.        ,  0.        , -0.12655778,  0.58021048, -0.09379026,\n",
       "         -0.35931907, -0.44439048, -0.00389845, -1.52068834, -0.46357277,\n",
       "         -0.12119992,  0.06986504,  0.95530827, -0.12492406,  0.94991673,\n",
       "          0.01397527,  0.35082508, -0.38790169, -0.32113828, -0.29406171],\n",
       "        [ 0.95466508,  0.94181703,  0.94201456,  0.95508686, -0.52893548,\n",
       "         -0.11221843, -0.61253322,  0.94657754,  0.94712468, -0.00574379,\n",
       "          0.94646575, -0.19959468, -0.13801868, -0.18676017, -0.72916086,\n",
       "          0.        ,  0.        , -0.12655778,  0.63073006, -0.22270911,\n",
       "         -0.38212788, -0.44720942, -0.02355147, -1.52460581, -0.46042271,\n",
       "         -0.12212641,  0.00619184,  0.95511002, -0.13765654,  0.9485376 ,\n",
       "          0.28429632,  0.31089967, -0.37397359, -0.31726105, -0.75281641]])}"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_date['2010-01-05']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "fa317577-7cd3-4b83-9db0-116b19fbcd75",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_n2n_cut = []\n",
    "y_n2n_cut = []\n",
    "for i in range(len(x_n2n)):\n",
    "    if len(x_n2n[i]) > 50:\n",
    "        x_n2n_cut.append(x_n2n[i][-50:-1])\n",
    "        y_n2n_cut.append(y_n2n[i][-50:-1])\n",
    "    else:\n",
    "        x_n2n_cut.append(x_n2n[i])\n",
    "        y_n2n_cut.append(y_n2n[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "8441d92f-de6c-48d8-b1c8-e1a1ee81ce28",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-47-86761ac1a6a5>:1: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
      "  pkl.dump(np.array(x_n2n_cut), open('./stock_x', 'wb'))\n",
      "<ipython-input-47-86761ac1a6a5>:2: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
      "  pkl.dump(np.array(y_n2n_cut), open('./stock_y', 'wb'))\n"
     ]
    }
   ],
   "source": [
    "pkl.dump(np.array(x_n2n_cut), open('./stock_x', 'wb'))\n",
    "pkl.dump(np.array(y_n2n_cut), open('./stock_y', 'wb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "80b21c21-29f2-426e-b832-5be85757ef97",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
